package dd.prog2.tutorium.tut3_23102012;

public abstract class Auto {
	protected String typ;
	protected String kennZ;
	protected double kmStand;
	protected double kmSinceInsp;
	protected boolean vermietet = false;
	protected double mietPreis;
	protected double check;

	public Auto(String kennZ, double kmStand){
		this.kennZ = kennZ;
		this.kmStand = kmStand;
	}

	public void rechnungErstellen(int mietdauer, double kmGefahren) throws Inspection{
		System.out.println(this.typ+": "+this.kennZ+". Km-Stand(Beginn): "+this.kmStand);
		System.out.println("Mietdauer: "+mietdauer+". Preis: "+(this.mietPreis*mietdauer));
		System.out.println("Km-Stand(Ende): "+(this.kmStand+kmGefahren));
		this.kmStand += kmGefahren;
		this.kmSinceInsp += kmGefahren;
		this.vermietet = false;
		if(this.kmSinceInsp > this.check){
			throw new Inspection(this);
		}
	}

	public void vermieten(){
		this.vermietet = true;
	}

	@Override
	public String toString() {
		String result = "";
		result = this.typ+": "+this.kennZ+"\nkm-Stand: "+this.kmStand+"\nStatus: "+(this.vermietet ? "vermietet" : "frei")+"\nletzte Inspektion: "+this.kmSinceInsp;
		return result;
	}


}
